import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router'
import MonthlyPass from '/@/views/monthlyPass/index.vue'
import Earnings from '/@/views/earnings/index.vue'
import Layout from '/@/layout/Index.vue'
import Home from '/@/views/tabbar/Home.vue'
import Category from '/@/views/tabbar/Category.vue'
import User from '/@/views/tabbar/User.vue'
import { useAppStore } from '/@/store'
import { getToken } from '/@/utils/auth'
import { t } from '/@/plugins/i18n'
// export const tabbar: Array<RouteRecordRaw> = [
//   {
//     path: '/home',
//     component: Home,
//     meta: {
//       title: 'home.title',
//       icon: 'home-o'
//     }
//   },
// ]
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: Layout,
    redirect: '/monthlyPass' //月卡
    // children: tabbar
  },
  {
    path: '/monthlyPass',
    component: MonthlyPass
  },
  {
    path: '/earnings', //提现
    component: Earnings
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由白名单
const whiteList = ['/login', '/monthlyPass']

router.beforeEach((to, from, next) => {
  const title = (to.meta.title as string) || 'Vite App'
  document.title = t(title)
  const token = getToken()
  next()
  // if (to.path === '/login' || whiteList.includes(to.path)) {
  //   if (token) {
  //     next('/')
  //   } else {
  //     next()
  //   }
  // } else {
  //   const store = useAppStore()
  //   if (!token) {
  //     store.setState({ title })
  //     return next('/login')
  //   }
  //
  //   store.setState({ title, token })
  //   next()
  // }
})

export default router
